PagesScripts.settings = {};

PagesScripts.settings.initHandlers = function() {
	if (!HTTPEvents.hasEventListener("onLogout")) {
		HTTPEvents.addEventListener("onLogout", PagesScripts.settings.onLogout);
	}
	PagesScripts.settings.drawLogin();
	PagesScripts.settings.loadSettings();
}

PagesScripts.settings.drawLogin = function() {
	if (Config.getParam("username") != null) {
		$("#loginBlock").hide();
		$("#logoutBlock").show();
		$("#loginUsername").html(Config.getParam("username"));
	}
	else {
		$("#loginBlock").show();
		$("#logoutBlock").hide();
	}
}

PagesScripts.settings.onLogout = function() {
	PagesScripts.settings.drawLogin();
}

PagesScripts.settings.setShowImages = function() {
	Config.setParam("showImages", $("#showImagesContainer").find("input[name='showImages']:checked").val());
}

PagesScripts.settings.loadSettings = function() {
	$("#showImagesContainer").find("input[name='showImages']").attr("checked", false).checkboxradio("refresh");
	if (Config.getParam("showImages") != null) {
		$("#showImagesContainer").find("input[name='showImages'][value='" + Config.getParam("showImages") + "']").attr("checked", true).checkboxradio("refresh");
	}
	else {
		$("#showImagesContainer").find("input[name='showImages'].eq(0)").attr("checked", true);
	}
}